#DBSCAN
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
plt.figure()

# 画个圈圈
X1, y1=datasets.make_circles(n_samples=5000, factor=.6,noise=.05)
#造一个聚类模型
X2, y2 = datasets.make_blobs(n_samples=1000, n_features=2, centers=[[1.2,1.2]], cluster_std=[[.1]],
               random_state=9)

X = np.concatenate((X1, X2))
plt.scatter(X[:, 0], X[:, 1], marker='o')
plt.title('data')
plt.show()
plt.figure()

from sklearn.cluster import KMeans
y_pred = KMeans(n_clusters=3, random_state=9).fit_predict(X)
plt.scatter(X[:, 0], X[:, 1], c=y_pred)
plt.title('k-means')
plt.show()
plt.figure()

from sklearn.cluster import DBSCAN
y_pred = DBSCAN().fit_predict(X)# 0.5, 5
plt.scatter(X[:, 0], X[:, 1], c=y_pred)
plt.title('dbscan')
plt.show()
plt.figure()

y_pred = DBSCAN(eps = 0.08, min_samples=3).fit_predict(X)
plt.title('dbscan eps = 0.08, min_samples=3')
plt.scatter(X[:, 0], X[:, 1], c=y_pred)
plt.show()
